home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / dhcp3 / dhclient-enter-hooks.d / samba < prev   
Encoding:
Text File  |  2008-10-10  |  1.7 KB  |  74 lines

  1. #!/bin/sh
  2.  
  3. SAMBA_DHCP_CONF=/etc/samba/dhcp.conf
  4.  
  5. netbios_setup() {
  6.     # No need to continue if we're called with an unsupported option
  7.  
  8.     if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] \
  9.        && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ] \
  10.        && [ "$reason" != EXPIRE ] && [ "$reason" != FAIL ]
  11.     then
  12.         return
  13.     fi
  14.  
  15.     umask 022
  16.  
  17.     local other_servers=""
  18.     local serverlist=""
  19.  
  20.     # the destination file won't exist yet on the first run after 
  21.     # installing samba
  22.     if [ -e $SAMBA_DHCP_CONF ]
  23.     then
  24.         # don't continue if no settings have changed
  25.         if [ "$new_netbios_name_servers" = "$old_netbios_name_servers" ] \
  26.            && [ "$new_netbios_scope" = "$old_netbios_scope" ]
  27.         then
  28.             return
  29.         fi
  30.  
  31.         # reparse our own file
  32.         other_servers=`sed -n -e"s/[[:space:]]$interface:[^[:space:]]*//g; \
  33.             s/^[[:space:]]*wins server[[:space:]]*=[[:space:]]*//pi" \
  34.             $SAMBA_DHCP_CONF`
  35.  
  36.         serverlist="$other_servers"
  37.     fi
  38.  
  39.     for server in $new_netbios_name_servers
  40.     do
  41.         serverlist="$serverlist $interface:$server"
  42.     done
  43.  
  44.     echo -n > ${SAMBA_DHCP_CONF}.new
  45.  
  46.     # If we're updating on failure/expire, AND there are no WINS
  47.     # servers for other interfaces, leave the file empty.
  48.     if [ -z "$other_servers" ]
  49.     then
  50.         if [ "$reason" = FAIL ] || [ "$reason" = EXPIRE ]
  51.         then
  52.             mv ${SAMBA_DHCP_CONF}.new $SAMBA_DHCP_CONF
  53.             return
  54.         fi
  55.     fi
  56.  
  57.     if [ -n "$serverlist" ]
  58.     then
  59.         echo "   wins server =$serverlist" >> ${SAMBA_DHCP_CONF}.new
  60.     fi
  61.     if [ -n "$new_netbios_scope" ]
  62.     then
  63.         echo "   netbios scope = $new_netbios_scope" >> ${SAMBA_DHCP_CONF}.new
  64.     fi
  65.     mv ${SAMBA_DHCP_CONF}.new $SAMBA_DHCP_CONF
  66.  
  67.     # reload the samba server
  68.     # We don't necessarily have the samba package installed. #414841
  69.     [ -x /etc/init.d/samba ] && /usr/sbin/invoke-rc.d samba reload
  70.  
  71. }
  72.  
  73. netbios_setup
  74.